package com.example.test.适配器模式;

import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import lombok.Setter;
import org.springframework.stereotype.Component;

//@Component
public class AdapterComponent {

    @Setter
    SourceBean sourceBean;

    public AdapterComponent(SourceBean sourceBean) {
        this.sourceBean = sourceBean;
    }

    public TargetBean getTargetBean() {
        TargetBean targetBean = new TargetBean();
        targetBean.setMethod(sourceBean.getName());

        JSONObject jsonObject = JSONUtil.parseObj(sourceBean);
        if (jsonObject.containsKey("name")) {
            jsonObject.remove("name");
        }

        targetBean.setParam(jsonObject);

        return targetBean;
    }
}
